<template>
	<view>
		<!-- <view class="cu-bar bg-white search">
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input type="text" v-model="searchObj.sname" placeholder="输入搜索的关键词" confirm-type="search"></input>
			</view>
			<view class="action">
				<button class="cu-btn bg-main round" @tap="search">搜索</button>
			</view>
		</view> -->
		<text v-for="(md,index) in mds" @tap="checkStore(md)" :key="index"
			class="padding-xs margin-xs bg-g-main text-main inline-block">{{md.sname}}</text>
		
		<view class="padding" v-if="mds.length < pageInfo.total">
			<button @click="loadMore" class="cu-btn block bg-main lg">显示更多</button>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			value: {
				default: "",
				type: String,
			},
		},
		computed: {
			currentPosition: function() {
				if (this.store.state.position) {
					return this.store.state.position;
				}
				return undefined;
			}
		},
		data: function() {
			return {
				searchObj: {
					sname: "",
				},
				pageInfo: {
					current: 1,
					size: 16,
					total: 0
				},
				mds: [],

			}
		},
		created: function() {
			this.search();
		},
		methods: {

			checkStore: function(md) {
				this.$emit("input", md.storeid);
				this.$emit("change", md);
			},
			search: function() {
				this.stores = [];
				this.pageInfo.current = 1;
				this.loadStore();
			},
			loadMore: function() {
				this.pageInfo.current++;
				this.loadStore();
			},
			loadStore: function() {
				let param = {
					current: this.pageInfo.current,
					size: this.pageInfo.size,
					sname: this.searchObj.sname,
					flg: true
				};
				if (this.currentPosition) {
					param.jd = this.currentPosition.jd;
					param.wd = this.currentPosition.wd;
				}

				this.api("/md/page").send(param).then(data => {
					this.pageInfo.current = data.astores.current;
					this.pageInfo.total = data.astores.total;
					this.pageInfo.size = data.astores.size;
					for (let index in data.astores.records) {
						let record = data.astores.records[index];
						if (record.distance) {
							record.distance = this.util.formatDistance(record.distance);
						}
						this.mds.push(record);
					}
				});

			},


		}

	}
</script>

<style>
</style>